package com.yze.headline;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.yze.headline.fragment.AttentionFragment;
import com.yze.headline.fragment.HomeFragment;
import com.yze.headline.fragment.NoLoginFragment;
import com.yze.headline.fragment.VrdioFragment;

public class HomeActivity extends AppCompatActivity implements View.OnClickListener{

    //点击控件
    LinearLayout linearLayout_first;
    LinearLayout linearLayout_vrdio;
    LinearLayout linearLayout_attention;
    LinearLayout linearLayout_nologin;
    RadioGroup radioGroup;
    //要改变状态的控件
    ImageView imageView_first;
    ImageView imageView_vrdio;
    ImageView imageView_attention;
    ImageView imageView_nologin;

    RadioButton rb_first;
    RadioButton rb_vrdio;
    RadioButton rb_attontion;
    RadioButton rb_nologin;

    private FrameLayout frameLayout;
    private FrameLayout videoLayout;
    private FrameLayout attentionLayout;
    private FrameLayout userLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        initView();
    }

    private void initView() {
        //点击事件ID
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        linearLayout_first = (LinearLayout) findViewById(R.id.linearLayout_first);
        linearLayout_vrdio = (LinearLayout) findViewById(R.id.linearLayout_vrdio);
        linearLayout_attention = (LinearLayout) findViewById(R.id.linearLayout_attention);
        linearLayout_nologin = (LinearLayout) findViewById(R.id.linearLayout_nologin);

        linearLayout_first.setOnClickListener(this);
        linearLayout_vrdio.setOnClickListener(this);
        linearLayout_attention.setOnClickListener(this);
        linearLayout_nologin.setOnClickListener(this);

        frameLayout=(FrameLayout)findViewById(R.id.frameLayout);
        //修改状态ID
        imageView_first = (ImageView) findViewById(R.id.imageView_first);
        rb_first = (RadioButton) findViewById(R.id.rb_first);
        imageView_first.setImageResource(R.drawable.b_newhome_tabbar_press);
        rb_first.setTextColor(Color.RED);
        getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new HomeFragment()).commit();

        imageView_vrdio = (ImageView) findViewById(R.id.imageView_vrdio);
        rb_vrdio = (RadioButton) findViewById(R.id.rb_vrdio);
        imageView_attention = (ImageView) findViewById(R.id.imageView_attontion);
        rb_attontion = (RadioButton) findViewById(R.id.rb_attontion);
        imageView_nologin = (ImageView) findViewById(R.id.imageView_nologin);
        rb_nologin = (RadioButton) findViewById(R.id.rb_nologin);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.linearLayout_first:
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new HomeFragment()).commit();
                imageView_first.setImageResource(R.drawable.b_newhome_tabbar_press);
                rb_first.setTextColor(Color.RED);
                imageView_vrdio.setImageResource(R.drawable.b_newvideo_tabbar);
                rb_vrdio.setTextColor(Color.BLACK);
                imageView_attention.setImageResource(R.drawable.b_newcare_tabbar);
                rb_attontion.setTextColor(Color.BLACK);
                imageView_nologin.setImageResource(R.drawable.b_newnologin_tabbar);
                rb_nologin.setTextColor(Color.BLACK);
                break;
            case R.id.linearLayout_vrdio:
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new VrdioFragment()).commit();
                imageView_first.setImageResource(R.drawable.b_newhome_tabbar);
                rb_first.setTextColor(Color.BLACK);
                imageView_vrdio.setImageResource(R.drawable.b_newvideo_tabbar_press);
                rb_vrdio.setTextColor(Color.RED);
                imageView_attention.setImageResource(R.drawable.b_newcare_tabbar);
                rb_attontion.setTextColor(Color.BLACK);
                imageView_nologin.setImageResource(R.drawable.b_newnologin_tabbar);
                rb_nologin.setTextColor(Color.BLACK);
                break;
            case R.id.linearLayout_attention:
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new AttentionFragment()).commit();
                imageView_first.setImageResource(R.drawable.b_newhome_tabbar);
                rb_first.setTextColor(Color.BLACK);
                imageView_vrdio.setImageResource(R.drawable.b_newvideo_tabbar);
                rb_vrdio.setTextColor(Color.BLACK);
                imageView_attention.setImageResource(R.drawable.b_newcare_tabbar_press);
                rb_attontion.setTextColor(Color.RED);
                imageView_nologin.setImageResource(R.drawable.b_newnologin_tabbar);
                rb_nologin.setTextColor(Color.BLACK);
                break;
            case R.id.linearLayout_nologin:
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new NoLoginFragment()).commit();
                imageView_first.setImageResource(R.drawable.b_newhome_tabbar);
                rb_first.setTextColor(Color.BLACK);
                imageView_vrdio.setImageResource(R.drawable.b_newvideo_tabbar);
                rb_vrdio.setTextColor(Color.BLACK);
                imageView_attention.setImageResource(R.drawable.b_newcare_tabbar);
                rb_attontion.setTextColor(Color.BLACK);
                imageView_nologin.setImageResource(R.drawable.b_newnologin_tabbar_press);
                rb_nologin.setTextColor(Color.RED);
                break;
            default:
                break;
        }
    }
}
